<template>
  <a-card :bordered="false">
    <div class="card-title">{{ $route.meta.title }}</div>
    <s-table
      ref="table"
      rowKey="help_id"
      :loading="isLoading"
      :columns="columns"
      :data="loadData"
      :pageSize="20"
    >
      <!-- 内容 -->
      <!-- 商品名称 -->
      <span slot="user" slot-scope="text,item">
         <p class="twoline-hide">{{ item.user.nick_name }}</p>
        <a title="点击查看原图" :href="text" target="_blank">
          <img width="50" height="50" :src="item.user.avatar_url" alt="加盟店铺图片" />
        </a>
      </span>
      <span slot="state" slot-scope="text,item">
          <span v-if="item.state == 0">审核中</span>
          <span v-else-if="item.state == 1" style="color: green">已通过</span>
          <span v-else style="color: red">已拒绝</span>
      </span>
      <!-- 操作项 -->
      <div class="actions" slot="action" slot-scope="text, item">
        <a @click="examine(item)" v-if="item.state == 0">审核</a>
      </div>
      <!-- 操作 -->
    </s-table>
    <Examine ref="Examine" @handleSubmit="handleRefresh" />
  </a-card>
</template>

<script>
  import * as Api from '@/api/costomers/index'
  import { STable } from '@/components'
  import {
    JoinTypeNum,
    Jtype
  } from '@/common/enum/join'
  import { Examine } from './modules'
  export default {
    name: 'Index',
    components: {
      STable,
      Examine
    },
    data () {
      return {
        JoinTypeNum,
        Jtype,
        // 查询参数
        queryParam: {},
        // 正在加载
        isLoading: false,
        // 表头
        columns: [
          {
            title: 'ID',
            dataIndex: 'id'
          },
          {
            title: '申请人',
            dataIndex: 'user',
            scopedSlots: { customRender: 'user' }
          },
          {
            title: '申请金额',
            dataIndex: 'price'
          },
          {
            title: '状态',
            dataIndex: 'state',
            scopedSlots: { customRender: 'state' }
          },
          {
            title: '申请时间',
            dataIndex: 'create_time'
          },
          {
            title: '操作',
            dataIndex: 'action',
            width: '180px',
            scopedSlots: { customRender: 'action' }
          }
        ],
        // 加载数据方法 必须为 Promise 对象
        loadData: param => {
          return Api.withdrawal({ ...param, ...this.queryParam })
            .then(response => {
              return response.data.list
            })
        }
      }
    },
    created () {

    },
    methods: {

      /**
       * 新增记录
       */
      handleAdd () {
        this.$refs.AddForm.add()
      },

      /**
       * 编辑记录
       */
      handleEdit (item) {
        this.$refs.EditForm.edit(item)
      },

      /**
       * 删除记录
       */
      handleDelete (item) {
      },

      /**
       * 刷新列表
       * @param Boolean bool 强制刷新到第一页
       */
      handleRefresh (bool = false) {
        this.$refs.table.refresh(bool)
      },

      /**
       * 检索查询
       */
      onSearch () {
        this.handleRefresh(true)
      },
      examine (item) {
        this.$refs.Examine.show(item)
      }
    }
  }
</script>
